import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:"/home"
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    beforeEnter:(to,from,next)=>{
      let token = window.localStorage.getItem("token");
      if(!token){
        next("/login");
        return
      }else{
        next();
    }
  }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/loginView.vue')
  },
  {
    path: '/rec',
    name: 'rec',
    component: () => import('../views/recView.vue')
  },
  {
    path: '/world',
    name: 'world',
    component: () => import('../views/worldView.vue')
  },
  
  {
    path: '/search',
    name: 'search',
    component: () => import('../views/searchView.vue')
  },
  {
    path: '/myspace',
    name: 'myspace',
    component: () => import('../views/myspaceView.vue'),
    beforeEnter:(to,from,next)=>{
      let token = window.localStorage.getItem("token");
      if(!token){
        next("/login");
        return
      }else{
        next();
    }
  }
  },
  {
    path: '/sele',
    name: 'sele',
    component: () => import('../views/seleView.vue')
  },
  {
    path: '/toplist',
    name: 'toplist',
    component: () => import('../views/toplistView.vue')
  },
  {
    path: '/kkb',
    name: 'kkb',
    component: () => import('../views/kkbView.vue')
  },
  {
    path: '/show',
    name: 'show',
    component: () => import('../views/showView.vue')
  },
  {
    path: '/pay',
    name: 'pay',
    component: () => import('../views/payView.vue')
  },
  {
    path: '/read',
    name: 'read',
    component: () => import('../views/readView.vue')
  },
  {
    path: '/checkmore',
    name: 'checkmore',
    component: () => import('../views/checkmoreView.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
